package game.poker.holdem.hand;

import game.poker.holdem.HoldEmUtils;
import game.poker.holdem.card.Card;
import game.poker.holdem.entity.Player;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Hand implements Comparable<Hand> {	
    /**
     * The intent of the use of set instead of a list is to avoid duplicate Card instances.
     */
	private final List<Card> cards;
	private final Long score;
	private final Ranking ranking;	
	
	private final Player player;
	
	public Hand(Player player, List<Card> cards, Ranking ranking, Long score) {
	    /* The set must contain exactly 5 cards. */
	    if(cards.size() != 5) {
	        throw new IllegalArgumentException(cards.size() + " is an valid number of cards to make a Hand!");
	    }
	    this.player = player;
		this.cards = Collections.unmodifiableList(new ArrayList<Card>(cards));
		this.ranking = ranking;
		this.score = score;
	}
	
	public List<Card> getCards() {
        return cards;
    }

    public Ranking getRanking() {
        return ranking;
    }

    public Player getPlayer() {
        return player;
    }
    
	public Long getScore() {
		return score;
	}

	@Override
	public int compareTo(Hand h) {		
		return score.compareTo(h.score);
	}
    
    public String handCardsToStringUnicodeImages() {
        StringBuilder sb = new StringBuilder();
        for(Card hC : cards) {
            sb.append(HoldEmUtils.toStringUnicodeImage(hC));
        }
        return sb.toString();
    }
}
